package dao;

import java.io.Serializable;
import java.util.List;

import modelo.Combobebida;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import util.HibernateUtil;

public class ComboBebidaDao implements Serializable{

	
	private static final long serialVersionUID = -4315696113126017299L;
	private Session session;
	SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
	
	public ComboBebidaDao() {
		super();
	}

	public ComboBebidaDao(Session session, SessionFactory sessionFactory) {
		super();
		this.session = session;
	}

	public List<Combobebida> obtenerComboBebida() {
		session=sessionFactory.openSession();
		
		Query query = session.createQuery("SELECT cb FROM ComboBebida cb");
		List<Combobebida> b = query.list();
		
		session.close();
		
		return b;
	}
	
	public Combobebida obtenerComboBebidaById(int id){
		session=sessionFactory.openSession();
		Query query = session.createQuery("from ComboBebida where IdComboBebida = :id ");
        query.setParameter("id", id);

        List<?> list = query.list();

        Combobebida cb = (Combobebida)list.get(0);
        return cb;
	}
	
	public void guardarComboBebida(Combobebida cb){
		session=sessionFactory.openSession();
		session.beginTransaction();
		session.saveOrUpdate(cb);
		session.getTransaction().commit();
		session.close();
	}

	public void eliminarComboBebida(Combobebida cb) {
		session=sessionFactory.openSession();
		session.beginTransaction();
		session.delete(cb);
		session.getTransaction().commit();
		session.close();
	}


}

